/****************************************************************************
	This file is part of Basqet.

	Basqet is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Basqet is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
    along with Basqet.  If not, see <http://www.gnu.org/licenses/>.

****************************************************************************/

#ifndef PAGENOTEWIDGET_H
#define PAGENOTEWIDGET_H

#include "notedata.h"
#include "commandmanager.h"
#include "uicapabilities.h"

#include <QtGui/QWidget>

#include <QPointer>

#include <QSize>
#include <QPoint>

class TextNoteData;
class RichTextEdit;
class TagManager;

class PageNoteWidgetEventFilter;
/** This class is intended to be used to show a note on a notepad-page. */

namespace Ui {
    class PageNoteWidget;
}

class PageNoteWidget : public QWidget
{
	Q_OBJECT

	public:
		// PageNoteWidget(PNoteData pNoteData, QWidget *parent = 0);
		PageNoteWidget(QExplicitlySharedDataPointer<NoteData> pNoteData,
					   QExplicitlySharedDataPointer<CommandManager> pCommandManager,
					   QExplicitlySharedDataPointer<TagManager> pTagManager,
					   QWidget *parent = 0);

		~PageNoteWidget();

	public slots:
		void activateInput();
		void cmdChangeGeometry(QPoint pos, QSize size);

		// Slots for formating.
		void setBold();
		void setItalic();
		void incFontSize();
		void decFontSize();
		void setUnderline();
		void setStrikethrough();
		void setLeft();
		void setRight();
		void setMid();

		// Slots for note-operations
		void actionDelete();

		// Act on UI-event for labels.
		void actionSetLable(QString lable, const QIcon& icon);

		// Act on label-changes from NoteData.
		void tagSet(QString tag);
		void tagCleared(QString tag);
		void tagChanged(QString oldTag, QString newTag);

	signals:
		void undo();
		void redo();

		void activated(QObject *, UICapabilities capabilities);
		// void deActivated(QObject *, UICapabilities::Capabilities capabilities);


	private slots:
		void startMoveOperation(QMouseEvent* e);
		void continueMoveOperation(QMouseEvent* e);
		void endMoveOperation(QMouseEvent* event);

		void noteRemoved();

		void splitterMoved(int pos, int index);
		void splitterInfo(const QList <int>& sizes);

		void editorActivated(QObject *, UICapabilities capabilities);


	protected:
		void changeEvent(QEvent *e);
		void focusInEvent(QFocusEvent * event);

	private:

		QExplicitlySharedDataPointer<CommandManager>	mCommandManager;
		QExplicitlySharedDataPointer<TagManager>		mTagManager;


		QPoint				mMoveOrigin;
		QPoint				mMoveWidgetOrgin;
		QSize				mWidgetResizeOrgin;

		bool				mMoveOperation;
		bool				mResizeOperation;


		QPointer<PageNoteWidgetEventFilter>			mGroupBoxFilter;
		QPointer<PageNoteWidgetEventFilter>			mTextAreaFilter;


		Ui::PageNoteWidget *m_ui;
		QExplicitlySharedDataPointer<NoteData>		mPNoteData;
		QPointer<TextNoteData>						mPTextNoteData;

		QPointer<RichTextEdit>						mPActiveEditor;
};

#endif // PAGENOTEWIDGET_H
